<!-- 
废弃：可以不需要看详情；也没有接口 
 -->
<template>
	<view style="padding-bottom: 50rpx;">
		<page-head :title="'套餐详情'" :headtype="2"></page-head>
		<view class="banner marginAuto" style="margin-top:10rpx;">
			<uv-swiper class="banner" height="200" :list="bannerdata" keyName="image"></uv-swiper>
		</view>
		<view class="goodsmsg marginAuto">
			<view class="goodsmsgname">{{ datas.name }}</view>
			<view class="goodsmsgb flex">
				<view class="jlq">{{ datas.min }}小时起约</view>
				<view class="jlq">{{ datas.sale_num }}已售</view>
			</view>
			<view class="goodsmsgday flex">
				<view class="goodsmsgdayl flex">
					<text style="color:#FC2A2A;font-size:30rpx;">￥{{ datas.price }}</text>
					<text style="color:#999999;font-size:24rpx;margin-left:20rpx;">￥{{ datas.old_price }}</text>
				</view>
				<view class="goodsmsgdayr">有效期:{{ datas.day }}天</view>
			</view>
		</view>
		<view class="drivesite flex marginAuto">
			<view class="drivesitetitle">试驾城市：</view>
			<view class="drivesiter flex" @click="$refs.siteref.open()">
				<view class="drivesiterno" style="color:#999999;" v-if="!opensiteac.name">请选择试驾城市</view>
				<view class="drivesitery" style="color: #333333;" v-if="opensiteac.name">{{ opensiteac.name }}</view>
				<uv-icon style="margin-top:2rpx;" name='arrow-right' size="16" color="#999999"></uv-icon>
			</view>
		</view>
		<view class="drivenum marginAuto flex">
			<view class="drivenumtitle">数量</view>
			<view class="drivenumnumf flex">
				<view class="drivenumeach drivenumjian" @click="jianfun()">-</view>
				<view class="drivenuminput">
					<input type="number" v-model="drnum"/>
				</view>
				<view class="drivenumeach drivenumjia" @click="jiafun">+</view>
			</view>
		</view>
		<view class="details">
			<view class="detailstitle marginAuto">详情信息</view>
			<view class="detailsmain marginAuto">
				<uv-parse :content="datas.detail"></uv-parse>
			</view>
		</view>
		<view class="marginAuto" style="width:600rpx;margin-top:60rpx;">
			<uv-button text="立即购买 " @click="buyfun()" :customStyle="{
				'background':'#1686F8',
				'color':'#ffffff',
				'font-size':'30rpx',
				'width':'600rpx',
				'height':'100rpx',
				'border-radius':'100rpx'
			}"></uv-button>
		</view>
		<!-- 购买 -->
		<view class="bottompopup">
			<view class="zg" v-if="iscarpay" @click="iscarpay = false"></view>
			<view class="pup" :class="iscarpay ? 'showtop':''" style="width:100%;">
				<view class="pupclose" @click="iscarpay = false">
					<uv-icon name="close" size="22" color="#222222"></uv-icon>
				</view>
				<view class="paypup">
					<view class="money"><text style="font-size: 20rpx;">￥</text>{{ paydata.amount }}</view>
					<view class="paytype">
						<view class="paytypetitle marginAuto">支付方式</view>
						<view class="paytypemain marginAuto">
							<view class="paytypeeach marginAuto flex" @click="paytype = 1">
								<view class="paytypeetitle">微信支付</view>
								<view class="paytypeer">
									<uv-icon name="checkmark-circle-fill" size="22" :color="paytype == 1 ? '#1686F8':'#E5E5E5'"></uv-icon>
								</view>
							</view>
							<!-- <view class="paytypeeach marginAuto flex" @click="paytype = 2">
								<view class="paytypeetitle">先验后付<text style="color: #9E9E9E;margin-left:16rpx;">0元下单，验车完成之后支付</text></view>
								<view class="paytypeer">
									<uv-icon name="checkmark-circle-fill" size="22" :color="paytype == 2 ? '#1686F8':'#E5E5E5'"></uv-icon>
								</view>
							</view> -->
							<view class="paytypeeach marginAuto flex" @click="apifun.navigate('/pages/home/discount','ordersn='+paydata.order_sn+'&apisite=/api/partnerDrive/getPartnerDriveOrderCouponList')">
								<view class="paytypeetitle">优惠券</view>
								<view class="paytypeer flex">
									<view class="rtxt" style="color:#999999;" v-if="!disitem.id">请选择</view>
									<view class="rtxt" style="color:#333;" v-if="disitem.id">￥10</view>
									<uv-icon name="arrow-right" size="16" color="#999999"></uv-icon>
								</view> 
							</view>
						</view>
					</view> 
				</view>
				<view class="marginAuto" style="width:600rpx;margin:60rpx auto;">
					<uv-button text="立即支付" @click="enterpay()" :customStyle="{
						'background':'#1686F8',
						'color':'#ffffff',
						'font-size':'30rpx',
						'width':'600rpx',
						'height':'100rpx',
						'border-radius':'100rpx'
					}"></uv-button>
				</view>
			</view>
		</view>
		<uv-picker ref="siteref" :columns="opensitedata" keyName="name" @confirm="entersite"></uv-picker>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				apifun:this.apifun,
				id:'',
				datas:{},
				bannerdata:[],
				opensitedata:[],
				opensiteac:{},
				drnum:1,
				iscarpay:false,
				paydata:{
					order_sn:'',
					amount:0
				},
				paytype:1,
				disitem:{},  // 优惠券
			};
		},
		onLoad(option) {
			this.id = option.id;
			this.initData();
			uni.$on('emitdiscount',(data)=>{  // 优惠券
				this.disitem = data.disitem;
			});
		},
		methods: {
			enterpay(){  // 立即支付
				let sendData = {
					user_coupon_id:this.disitem.id || '',
					pay_type:this.paytype,
					order_sn:this.paydata.order_sn || ''
				}
				this.apifun.unirequest('/api/partnerDrive/payPartnerDriveOrder','post',sendData,(res)=>{
					// console.log(res)
					if(res.code === 200){
						let datas = res.data;
						this.apifun.wxpaymini(datas,()=>{
							this.apifun.navigate('/pages/accompany/mealpaysuc');
						})
					}else{
						this.apifun.toast(res.msg)
					}
				})
			},
			buyfun(){
				let sendData = {
					id:this.id,
					city_id:this.opensiteac.id || '',
					num:this.drnum
				};
				this.apifun.unirequest('/api/partnerDrive/createEscortMenuOrder','post',sendData,(res)=>{
					if(res.code === 200){
						let datas = res.data;
						this.paydata = datas;
						this.iscarpay=true;
					}else{
						this.apifun.toast(res.msg)
					}
				});
			},
			initData(){
				let sendData = {
					id:this.id
				}
				this.apifun.unirequest('/api/partnerDrive/getEscortMenuInfo','post',sendData,(res)=>{
					// console.log(res)
					if(res.code === 200){
						let datas = res.data;
						this.datas = datas;
						this.bannerdata = [{
							"image":this.apifun.URLimg+datas.image,
						}];
						
						this.opensitedata = [[...datas.city]];
					}else{
						this.apifun.toast(res.msg)
					}
				})
			},
			entersite(e){
				this.opensiteac = e.value[0];
			},
			jiafun(){
				let drnum = this.drnum;
				if(drnum < this.datas.total){
					++drnum;
					this.drnum = drnum
				}else{
					this.apifun.toast('已达到可购买上限')
				}
			},
			jianfun(){
				let drnum = this.drnum;
				if(drnum > 1){
					--drnum;
					this.drnum = drnum
				}
			}
		},
	};
</script>

<style scoped lang="scss">
	@import '../../public/popupb.scss';
	page{
		padding-bottom: 50rpx
	}
	.banner{
		position: relative;
		z-index: 10;
		width:100%;
		height: 400rpx;
	}
	.goodsmsg{
		width: 650rpx;
		padding: 20rpx;
		margin-top: 20rpx;
		background: #fff;
		border-radius: 20rpx;
		.goodsmsgname{
			font-size: 34rpx;
			color: #222222;
		}
		.goodsmsgb{
			margin: 10rpx 0;
			.jlq{
				display: inline-block;
				padding:0 10rpx;
				background:#E7F2FF;
				color:#0089FB;
				font-size:20rpx;
				border-radius:6rpx;
				height:50rpx;
				line-height:50rpx;
				margin-right: 10rpx;
			}
			
		}
		.goodsmsgday{
			justify-content: space-between;
			line-height: 60rpx;
			.goodsmsgdayl{
				line-height: 60rpx;
			}
			.goodsmsgdayr{
				font-size:24rpx;
				color: #666666;
			}
		}
	}
	.drivesite{
		width: 650rpx;
		padding: 20rpx;
		margin-top: 20rpx;
		justify-content: space-between;
		background: #fff;
		border-radius: 20rpx;
		.drivesitetitle{
			font-size: 28rpx;
			color: #333333;
			line-height: 60rpx;
		}
		.drivesiter{
			font-size: 30rpx;
			line-height: 60rpx;
		}
	}
	// 数量
	.drivenum{
		width: 650rpx;
		padding: 20rpx;
		background: #fff;
		border-radius: 20rpx;
		margin-top: 20rpx;
		justify-content: space-between;
		.drivenumtitle{
			line-height: 60rpx;
			color:#333333;
			font-size: 28rpx;
		}
		.drivenumnumf{
			width: 210rpx;
			.drivenumeach{
				background: #DFF1FF;
				width: 60rpx;
				height: 60rpx;
				line-height: 60rpx;
				color:#0089FB;
				font-size: 30rpx;
				text-align: center;
				border-radius: 20rpx;
			}
			.drivenuminput{
				width: 80rpx;
				height: 60rpx;
				input{
					text-align: center;
					height: 60rpx;
					line-height: 60rpx;
					color: #222222;
					font-size: 30rpx;
				}
			}
		}
	}
	// 详情信息
	.details{
		.detailstitle{
			width: 690rpx;
			height: 30rpx;
			line-height: 30rpx;
			border-left:4rpx solid #0089FB;
			padding-left: 10rpx;
			margin:20rpx auto;
		}
		.detailsmain{
			width: 630rpx;
			padding: 30rpx;
			background: #fff;
			border-radius: 20rpx;
			color:#333333;
			font-size: 30rpx;
			line-height:44rpx;
		}
	}
	
	
	// --支付方式popup
	.paypup{
		.money{
			padding: 80rpx 0 40rpx;
			color: #222222;
			font-size: 60rpx;
			text-align: center;
		}
		.paytype{
			.paytypetitle{
				width: 690rpx;
				font-size: 28rpx;
				color: #222222;
			}
			.paytypemain{
				.paytypeeach{
					width: 630rpx;
					margin-top: 20rpx;
					padding: 20rpx 30rpx;
					background:#F6F6F6;
					border-radius: 20rpx;
					justify-content: space-between;
					.paytypeetitle{
						color: #222222;
						font-size: 30rpx;
						line-height: 50rpx;
					}
					.paytypeer{
						.rtxt{
							font-size:30rpx;
						}
					}
				}
			}
		}
	}
</style>